package tech.tongyu.bob.demo.proxy.jdkproxy.service.impl;

import org.springframework.stereotype.Service;
import tech.tongyu.bob.demo.proxy.jdkproxy.proxy.TransactionProxy;
import tech.tongyu.bob.demo.proxy.jdkproxy.service.UserService;

@Service
public class UserServiceImpl implements UserService {
    @Override
    public void registerUser(String username, String email) {
        System.out.println("Checking if user exists...");
        // 检查用户是否存在的逻辑

        System.out.println("Saving user to database...");
        // 保存用户信息到数据库的逻辑

        System.out.println("Sending welcome email...");
        // 发送欢迎邮件的逻辑
        UserService proxy = TransactionProxy.createProxy(this);
        proxy.login(username);  // 通过代理对象调用
    }

    @Override
    public void login(String username) {
        this.internalMethod();
    }

    @Override
    public final void internalMethod() {
        System.out.println("内部方法");
        System.out.println("检查用户是否存在");
        System.out.println("检查账号密码");
        System.out.println("登录成功");
    }


}